//
//  VisitorLoginView.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/10/20.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "VisitorLoginView.h"
#import "Masonry.h"
#import "BaseTableViewController.h"
#import "UIlabel+extension.h"
#import "UIButton+extesion.h"
#import "OAuthViewController.h"

@interface VisitorLoginView()<VisitorLoginViewDelegate>

@end


@implementation VisitorLoginView


- (void) loginButtonDidClick{
    
    if ([self.delegate respondsToSelector:@selector(userWillLogin)]) {
        
       NSLog(@"hahahahah");
        // 调用代理对象的登录方法，代理对象去实现登录方法
        [self.delegate userWillLogin];
    }
    
}

- (void) registerButtonDidClick{
    
    if ([self.delegate respondsToSelector:@selector(userWillRegister)]) {
        // 调用代理对象的登录方法，代理对象去实现登录方法
        [self.delegate userWillRegister];
    }
    
    
}


#pragma mark :纯代码创建UIview的入口方法
- (instancetype)initWithFrame:(CGRect)frame{

    if(self = [super initWithFrame:frame]){
        BaseTableViewController *basecontroller = [[BaseTableViewController alloc]init];
        
       self.delegate = basecontroller;
       
        [self setUpUI];
                
    }
    return self;
}


- (void)startAnimation{
    
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    anim.repeatCount = MAXFLOAT;
    anim.fromValue = 0;
//    注意遇到问题,勤用google 百度
    anim.toValue = @(2*M_PI);
    anim.duration = 20;
    anim.removedOnCompletion = false;
    [_circleIcon.layer addAnimation:anim forKey:nil];
}

- (void)setUpInfoWithlabelText:(NSString *)labelText andimageName:(NSString *)imageName{
    
    self.tipLable.text = labelText;
    if (imageName != nil) {
        self.circleIcon.image = [UIImage imageNamed:imageName];
        self.largeHouse.hidden = true;
    }
    else{
//        在首页面
    }
}

#pragma mark :进行控件的约束
-(void)layoutSubviews{
    
    [_circleIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_circleIcon.superview.mas_centerX);
        make.centerY.equalTo(_circleIcon.superview.mas_centerY).offset(-80);
    }];
    
    [_backImage mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_circleIcon.mas_centerX);
        make.centerY.equalTo(_circleIcon.mas_centerY);
        
    }];
    
    
    [_largeHouse mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_circleIcon.mas_centerX);
        make.centerY.equalTo(_circleIcon.mas_centerY);
        
    }];
    
    [_tipLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_circleIcon.mas_centerX);
        make.centerY.equalTo(_circleIcon.mas_bottom).offset(16);
        make.width.mas_equalTo(230);
//        make.height.mas_equalTo(40);
        
    }];
    
    [_loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_circleIcon.mas_left);
        make.top.equalTo(_tipLable.mas_bottom).offset(16);
        make.width.mas_equalTo(70);
    }];
    
    
    [_registerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_circleIcon.mas_right);
        make.top.equalTo(_tipLable.mas_bottom).offset(16);
        make.width.mas_equalTo(70);
    }];
    
}



#pragma mark :懒加载,切记,懒加载的判断条件是前面要加!的
-(UIImageView *)circleIcon{
    if (!_circleIcon) {
        _circleIcon = [[UIImageView alloc]init];
        _circleIcon.image = [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"];
    }
    return _circleIcon;
}

-(UIImageView *)largeHouse{
    if (!_largeHouse) {
        _largeHouse = [[UIImageView alloc]init];
        _largeHouse.image = [UIImage imageNamed:@"visitordiscover_feed_image_house"];
    }
    return _largeHouse;
    
}

-(UIImageView *)backImage{
    if (!_backImage) {
        _backImage = [[UIImageView alloc]init];
        _backImage.image = [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"];
    }
    return _backImage;
    
}

-(UIButton *)loginBtn{
    if (!_loginBtn) {
        
        UIColor *color = [UIColor darkGrayColor];
        _loginBtn = [[UIButton_extesion alloc]initWithTitle:@"登录" titleColor:color imageName:@"common_button_white_disable"];
//        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
//        [_loginBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
//        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        
        
}
    return _loginBtn;
}

-(UIButton *)registerButton{
    
    if (!_registerButton) {
        UIColor *color = [UIColor orangeColor];

        _registerButton = [[UIButton_extesion alloc]initWithTitle:@"注册" titleColor:color imageName:@"common_button_white_disable"];
//        [_registerButton setTitle:@"注册" forState:UIControlStateNormal];
//        [_registerButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//        [_registerButton setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
    }
    return _registerButton;
}


//注意调用UIlabel的子类的扩展方法时,用子类的类名或者对象来调用

-(UILabel *)tipLable{
    
    if (!_tipLable) {
        
        UIColor *color = [UIColor lightGrayColor];
//        _tipLable = [UIlabel_extension factoryLabel:@"关注一些人,回这里来看看有什么惊喜" fontsize:14 textColor: color];
        
        _tipLable = [[UIlabel_extension alloc]initWithtext:@"关注一些人,回这里来看看有什么惊喜" fontsize:14 textColor:color];
        
//        _tipLable.text = @"关注一些人,回这里来看看有什么惊喜";
//        _tipLable.textColor = [UIColor lightGrayColor];
//        _tipLable.font = [UIFont systemFontOfSize:14];
//        _tipLable.numberOfLines = 0;
//        _tipLable.textAlignment = NSTextAlignmentCenter;
//        [_tipLable sizeToFit];
        
        
    }
    return _tipLable;
}
                     

- (void)setUpUI{
    
    
//    BaseTableViewController *basecontroller = [[BaseTableViewController alloc]init];
    
    [self addSubview:self.circleIcon];
    [self addSubview:self.backImage];
    [self addSubview:self.largeHouse];
    [self addSubview:self.loginBtn];
    [self addSubview:self.registerButton];
    [self addSubview:self.tipLable];
    self.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
    
    [self.loginBtn addTarget:self action:@selector(loginButtonDidClick) forControlEvents:UIControlEventTouchUpInside ];
    
    [self.registerButton addTarget:self action:@selector(registerButtonDidClick) forControlEvents:UIControlEventTouchUpInside ];

}

@end
